<template>
  <div class="login-page">
    <div class="login-container">
      <!-- 左侧图片区域 -->
      <div class="login-banner" :style="{ backgroundImage: `url(${bgImage})` }">
        <div class="banner-overlay"></div>
        <div class="floating-particles">
          <span v-for="n in 8" :key="n" class="particle"></span>
        </div>
        <div class="banner-content">
          <div class="logo-area">
            <div class="logo-icon-wrapper">
              <icon-image class="logo-icon"/>
            </div>
            <h2 class="logo-text">协创视界</h2>
          </div>

          <div class="slogan-container">
            <div class="slogan-en">
              <div>We See What You Imagine</div>
              <div>We Create What You Dream</div>
            </div>

            <div class="slogan-divider"></div>

            <div class="slogan-cn">
              <div>所见即所创</div>
              <div>协创即共赢</div>
              <div>让每个像素抵达可能</div>
            </div>
          </div>

          <div class="banner-features">
            <div class="feature-item">
              <div class="feature-icon-wrapper">
                <icon-calendar class="feature-icon"/>
              </div>
              <span>高效协作</span>
            </div>
            <div class="feature-item">
              <div class="feature-icon-wrapper">
                <icon-palette class="feature-icon"/>
              </div>
              <span>创意设计</span>
            </div>
            <div class="feature-item">
              <div class="feature-icon-wrapper">
                <icon-share-alt class="feature-icon"/>
              </div>
              <span>即时共享</span>
            </div>
          </div>
        </div>
      </div>

      <!-- 右侧登录表单区域 -->
      <div class="login-form-wrapper">
        <div class="login-form-container">
          <div class="login-header">
            <h1 class="welcome-title">hello !</h1>
            <p class="welcome-subtitle">欢迎来到协创视界！</p>
          </div>

          <a-form :model="formState" class="login-form" @submit="handleSubmit">
            <div class="form-fields">
              <div class="form-group">
                <label class="field-label">
                  <span class="required-mark">*</span>账号
                </label>
                <a-input
                    v-model="formState.username"
                    placeholder="请输入用户名"
                    allow-clear
                >
                  <template #prefix>
                    <icon-user/>
                  </template>
                </a-input>
              </div>

              <div class="form-group">
                <label class="field-label">
                  <span class="required-mark">*</span>密码
                </label>
                <a-input
                    v-model="formState.password"
                    type="password"
                    placeholder="请输入密码"
                    allow-clear
                >
                  <template #prefix>
                    <icon-lock/>
                  </template>
                </a-input>
              </div>
            </div>

            <div class="login-options">
              <a-checkbox v-model="rememberMe">记住我</a-checkbox>
              <a-link class="forgot-password">忘记密码？</a-link>
            </div>

            <div class="login-action-area">
              <a-button
                  type="primary"
                  html-type="submit"
                  class="login-button"
                  :loading="loading"
              >
                登录
              </a-button>
            </div>
          </a-form>

          <div class="login-footer">
            <p>@协创视界</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref, reactive, onMounted} from 'vue';
import {Message} from '@arco-design/web-vue';
import {useRouter} from 'vue-router';
import {
  IconUser,
  IconLock,
  IconImage,
  IconCalendar,
  IconPalette,
  IconShareAlt
} from '@arco-design/web-vue/es/icon';

import type {UserLoginRequest} from "../service/typing";
import {userLoginRequestByPost} from "../service/userRequest";
import {useUserStore} from "../stores/useUserStore";

// 背景图片URL
const bgImage = ref('https://images.pexels.com/photos/7054528/pexels-photo-7054528.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2');

// 响应式状态
const router = useRouter();
const userStore = useUserStore()
const loading = ref(false);
const rememberMe = ref(false)
const formState = reactive<UserLoginRequest>({
  username: "",
  password: "",
  platform: 2
})

// 登录处理
const handleSubmit = async () => {
  loading.value = true;

  try {
    const res = await userLoginRequestByPost(formState)
    console.log(res);
    if (res.code!=200){
      Message.warning("登录失败")
      return
    }
    // 登录成功
    Message.success('登录成功');
    userStore.setLoginUser(res.data)
    router.push('/');
  } catch (error) {
    Message.error('登录失败，请检查用户名和密码');
  } finally {
    loading.value = false;
  }
};

onMounted(async () => {

});
</script>

<style scoped>
:root {
  --theme-color: #4C8DFF;
  --theme-color-dark: #2B6FF0;
  --theme-color-light: #74A6FF;
}

.login-page {
  height: 100vh;
  width: 100vw;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f5f7fb;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
}

.login-container {
  display: flex;
  width: 100%;
  height: 100%;
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  background-color: #fff;
}

/* 左侧图片区域 */
.login-banner {
  flex: 1;
  position: relative;
  background-color: #4C8DFF;
  /* 调整背景图片的定位和大小 */
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  transition: background-image 0.5s ease-in;
}

.banner-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  /* 调整渐变背景，增加深度，使图片内容更清晰 */
  background: linear-gradient(125deg,
  rgba(76, 141, 255, 0.95),
  rgba(43, 111, 240, 0.98),
  rgba(30, 98, 230, 0.97));
  z-index: 1;
}

/* 浮动粒子效果 */
.floating-particles {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  overflow: hidden;
}

.particle {
  position: absolute;
  display: block;
  background-color: rgba(255, 255, 255, 0.25);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: float 15s infinite ease-in-out;
}

.particle:nth-child(1) {
  top: 25%;
  left: 10%;
  width: 12px;
  height: 12px;
  animation-delay: 0s;
  animation-duration: 20s;
}

.particle:nth-child(2) {
  top: 40%;
  left: 20%;
  width: 10px;
  height: 10px;
  animation-delay: 2s;
  animation-duration: 18s;
}

.particle:nth-child(3) {
  top: 60%;
  left: 15%;
  width: 8px;
  height: 8px;
  animation-delay: 4s;
  animation-duration: 22s;
}

.particle:nth-child(4) {
  top: 20%;
  left: 80%;
  width: 14px;
  height: 14px;
  animation-delay: 1s;
  animation-duration: 25s;
}

.particle:nth-child(5) {
  top: 70%;
  left: 85%;
  width: 10px;
  height: 10px;
  animation-delay: 3s;
  animation-duration: 19s;
}

.particle:nth-child(6) {
  top: 30%;
  left: 60%;
  width: 12px;
  height: 12px;
  animation-delay: 5s;
  animation-duration: 24s;
}

.particle:nth-child(7) {
  top: 80%;
  left: 40%;
  animation-delay: 6s;
  animation-duration: 26s;
}

.particle:nth-child(8) {
  top: 10%;
  left: 30%;
  width: 15px;
  height: 15px;
  animation-delay: 7s;
  animation-duration: 28s;
}

@keyframes float {
  0% {
    transform: translateY(0px) translateX(0px) rotate(0deg);
    opacity: 0.2;
  }
  25% {
    transform: translateY(-20px) translateX(10px) rotate(90deg);
    opacity: 0.4;
  }
  50% {
    transform: translateY(-40px) translateX(-10px) rotate(180deg);
    opacity: 0.6;
  }
  75% {
    transform: translateY(-20px) translateX(10px) rotate(270deg);
    opacity: 0.4;
  }
  100% {
    transform: translateY(0px) translateX(0px) rotate(360deg);
    opacity: 0.2;
  }
}

.banner-content {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px;
  position: relative;
  z-index: 3;
  text-align: center;
}

.logo-area {
  display: flex;
  align-items: center;
  margin-bottom: 60px;
}

.logo-icon-wrapper {
  width: 78px;
  height: 78px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1),
  inset 0 2px 4px rgba(255, 255, 255, 0.3);
  margin-right: 20px;
  position: relative;
  overflow: hidden;
  transform: rotate(-5deg);
}

.logo-icon-wrapper::before {
  content: '';
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
  background: linear-gradient(45deg, transparent 40%, rgba(255, 255, 255, 0.3) 50%, transparent 60%);
  animation: shine 3s infinite linear;
}

@keyframes shine {
  0% {
    transform: translateX(-200%) translateY(-200%);
  }
  100% {
    transform: translateX(200%) translateY(200%);
  }
}

.logo-icon {
  font-size: 38px;
  color: white;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.logo-text {
  font-size: 38px;
  font-weight: bold;
  margin: 0;
  letter-spacing: 1px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  background: linear-gradient(to right, #ffffff, #e0e0ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Slogan 样式 */
.slogan-container {
  margin-bottom: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 520px;
}

.slogan-en {
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 24px;
  line-height: 1.5;
  letter-spacing: 0.5px;
  opacity: 0.95;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.slogan-divider {
  width: 80px;
  height: 3px;
  background: rgba(255, 255, 255, 0.7);
  margin-bottom: 24px;
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.slogan-divider::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(to right, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0));
  animation: shine-divider 2s infinite;
}

@keyframes shine-divider {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

.slogan-cn {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.8;
  letter-spacing: 1px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* 特性列表 */
.banner-features {
  display: flex;
  justify-content: center;
  gap: 40px;
  margin-top: 20px;
}

.feature-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  transition: transform 0.3s ease;
}

.feature-item:hover {
  transform: translateY(-8px);
}

.feature-icon-wrapper {
  position: relative;
  width: 70px;
  height: 70px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(5px);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1),
  inset 0 1px 3px rgba(255, 255, 255, 0.3);
  overflow: hidden;
  transition: all 0.3s ease;
}

.feature-icon-wrapper::before {
  content: '';
  position: absolute;
  width: 150%;
  height: 150%;
  background: linear-gradient(
      to bottom right,
      rgba(255, 255, 255, 0),
      rgba(255, 255, 255, 0.1),
      rgba(255, 255, 255, 0)
  );
  transform: rotate(45deg) translate(-20%, -20%);
  animation: sweep 3s infinite linear;
  z-index: 1;
}

@keyframes sweep {
  0% {
    transform: rotate(45deg) translate(-100%, -100%);
  }
  100% {
    transform: rotate(45deg) translate(100%, 100%);
  }
}

.feature-item:hover .feature-icon-wrapper {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
  box-shadow: 0 15px 25px rgba(0, 0, 0, 0.15),
  inset 0 2px 5px rgba(255, 255, 255, 0.5);
}

.feature-icon {
  font-size: 32px;
  color: white;
  z-index: 2;
  position: relative;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.2));
}

.feature-item span {
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* 右侧登录表单区域 */
.login-form-wrapper {
  width: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  background-color: #fff;
  position: relative;
  overflow: auto;
  box-shadow: -5px 0 20px rgba(0, 0, 0, 0.1);
}

.login-form-container {
  width: 100%;
  max-width: 360px;
  background-color: #fff;
  border-radius: 8px;
  padding: 32px;
  box-shadow: 0 4px 20px rgba(76, 141, 255, 0.1);
}

.login-header {
  margin-bottom: 32px;
  text-align: center;
}

.welcome-title {
  font-size: 3rem;
  font-weight: bold;
  color: #4C8DFF;
  margin-bottom: 8px;
  position: relative;
  display: inline-block;
}

.welcome-title::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  width: 40px;
  height: 4px;
  background-color: #4C8DFF;
  border-radius: 2px;
  transform: translateX(-50%);
}

.welcome-subtitle {
  font-size: 1.2rem;
  color: #717790;
  margin: 0;
}

.login-form {
  margin-bottom: 24px;
}

.form-fields {
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 20px;
}

.field-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: #333945;
  margin-bottom: 8px;
}

.required-mark {
  color: #f53f3f;
  margin-right: 4px;
}

.login-form :deep(.arco-input-wrapper) {
  background-color: #f8faff;
  border-color: #e0e7ff;
  height: 44px;
}

.login-form :deep(.arco-input-wrapper:hover),
.login-form :deep(.arco-input-wrapper:focus-within) {
  border-color: #4C8DFF;
  background-color: #fff;
  box-shadow: 0 0 0 2px rgba(76, 141, 255, 0.1);
}

.login-options {
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
  font-size: 14px;
}

.forgot-password {
  color: #4C8DFF;
}

.login-action-area {
  text-align: center;
  margin-bottom: 16px;
}

.login-button {
  height: 44px;
  font-size: 16px;
  background-color: #4C8DFF;
  border-color: #4C8DFF;
  transition: all 0.3s ease;
  border-radius: 6px;
  width: 100%;
  margin: 0 auto;
}

.login-button:hover {
  background-color: #2B6FF0;
  border-color: #2B6FF0;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(76, 141, 255, 0.3);
}

.login-actions {
  text-align: center;
  margin-top: 16px;
  color: #717790;
  font-size: 14px;
}

.register-link {
  color: #4C8DFF;
  margin-left: 8px;
  font-weight: 500;
}

.login-footer {
  margin-top: 48px;
  text-align: center;
  color: #717790;
  font-size: 14px;
}

/* 响应式样式 */
@media (max-width: 1200px) {
  .logo-icon-wrapper {
    width: 70px;
    height: 70px;
  }

  .feature-icon-wrapper {
    width: 60px;
    height: 60px;
  }

  .feature-icon {
    font-size: 28px;
  }
}

@media (max-width: 992px) {
  .login-form-wrapper {
    width: 55%;
    padding: 30px;
  }

  .login-banner {
    width: 45%;
  }

  .logo-icon-wrapper {
    width: 60px;
    height: 60px;
  }

  .logo-icon {
    font-size: 32px;
  }

  .logo-text {
    font-size: 32px;
  }

  .feature-icon-wrapper {
    width: 50px;
    height: 50px;
  }

  .feature-icon {
    font-size: 24px;
  }

  .particle {
    opacity: 0.4;
  }
}

@media (max-width: 768px) {
  .login-container {
    flex-direction: column;
  }

  .login-banner {
    display: none;
  }

  .login-form-wrapper {
    width: 100%;
    height: 100%;
    padding: 40px 30px;
    box-shadow: none;
  }

  .login-form-container {
    max-width: 400px;
    padding: 24px;
  }
}

@media (max-width: 576px) {
  .login-form-wrapper {
    padding: 30px 20px;
  }

  .welcome-title {
    font-size: 2.5rem;
  }

  .welcome-subtitle {
    font-size: 1rem;
  }

  .login-form-container {
    max-width: 100%;
    box-shadow: none;
    padding: 0;
  }

  .login-button {
    height: 44px;
  }
}
</style> 